package com.igeekhome.ccs.controller;

import com.igeekhome.ccs.biz.IHaterBiz;
import com.igeekhome.ccs.entity.Customer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Service
@RequestMapping("/hater")
public class HaterController {
    @Autowired
    private IHaterBiz biz;

    /**
     * 已测试
     * 获得全部拉黑客户
     * @return
     */
    @GetMapping("/get/all")
    @ResponseBody
    public List<Customer> getAll(){
        List<Customer> list = biz.getAll();
        if(list.size()==0){
            System.out.println("无拉黑客户");
        }
        return list;
    }


    @GetMapping("/get/grade")
    @ResponseBody
    public List<Customer> getByGrade(String grade){
        List<Customer> list = biz.queryByGrade(grade);
        if(list.size()==0){
            System.out.println("未查询到拉黑用户");
        }
        return list;
    }

    @GetMapping("/get/source")
    @ResponseBody
    public List<Customer> queryBySource(String source){
        List<Customer> list = biz.queryBySource(source);
        if(list.size()==0){
            System.out.println("未查询到拉黑用户");
        }
        return list;
    }

    @GetMapping("/get/keywords")
    @ResponseBody
    public List<Customer> queryBykeywords(String keywords){
        List<Customer> list = biz.queryByGrade(keywords);
        list.removeAll(biz.queryBySource(keywords));
        list.addAll(biz.queryBySource(keywords));

        list.removeAll(biz.queryByName(keywords));
        list.addAll(biz.queryByName(keywords));

        list.removeAll(biz.queryByRealName(keywords));
        list.addAll(biz.queryByRealName(keywords));

        list.removeAll(biz.queryByPhone(keywords));
        list.addAll(biz.queryByPhone(keywords));

        list.removeAll(biz.queryByEmail(keywords));
        list.addAll(biz.queryByEmail(keywords));
        if(list.size()==0){
            System.out.println("未查询到拉黑用户");
        }
        return list;
    }



    @DeleteMapping("/free")
    @ResponseBody
    public int free(int id){
        return biz.free(id);
    }
    @DeleteMapping("/freeBatch")
    @ResponseBody
    public int freeBatch(@RequestParam("ids[]") List<Integer> ids){
        return biz.freeBatch(ids);//返回的是删除的个数
    }
}
